<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
  <style>
    .login {
      background-color: yellowgreen;
    }

    .register {
      background-color: pink;
    }
  </style>
</head>

<body>
  <div id="app">
    <!-- 点击改变isLogin的状态渲染对应的form -->
    <div>
      <button @click="isLogin = true">登录</button>
      <button @click="isLogin = false">注册</button>
    </div>

    <!-- 添加key避免diff算法把元素复用 -->
    <form v-if="isLogin" class="login" key = "laoliu">
      <input type="text" name="username">
      <input type="password" name="password">
    </form>

    <!-- 添加key避免diff算法把元素复用 -->
    <form v-else class="register" key = "laolang">
      <input type="text" name="username">
      <input type="password" name="password">
    </form>

  </div>
  <script>
    Vue.config.productionTip = false;

    const vm = new Vue({
      el: "#app",
      data() {
        return {
          isLogin: true
        }
      }
    })
  </script>
</body>

</html>